import { message } from 'antd';

class GlobalSetting {
  private static instance: GlobalSetting;
  private _hide: Function = null;
  private _isServer: boolean = false;
  private constructor() {
    // do something construct...
  }

  static getInstance() {
    if (!GlobalSetting.instance) {
        GlobalSetting.instance = new GlobalSetting();
        // ... any one time initialization goes here ...
    }
    return GlobalSetting.instance;
  }

  /**
   * 判断是否为服务器模式
   */
  get isServer(): boolean {
      return this._isServer;
  }
  set isServer(value: boolean) {
      this._isServer = value;
  }

  /**
   * 显示加载信息
   * 全局只显示一个
   * @param msg
   */
  public showLoadingMsg(msg: string) {
    // 如果已经又消息在显示中，先清空
    this.hideLoadingMsg();
    this._hide = message.loading(msg, 0);
  }

  /**
   * 关闭加载信息
   * 全局唯一
   */
  public hideLoadingMsg() {
    if (this._hide != null) {
      this._hide();
      this._hide = null;
    }
  }

}

const instance: GlobalSetting = GlobalSetting.getInstance();
export default instance;
